package com.administrator.kotlindemo1.adapter

import android.content.Context
import android.util.Log
import android.view.View
import android.widget.TextView
import com.administrator.kotlindemo1.R
import com.administrator.kotlindemo1.bean.Person
import com.hazz.kotlinmvp.view.recyclerview.ViewHolder
import com.hazz.kotlinmvp.view.recyclerview.adapter.CommonAdapter
import com.hazz.kotlinmvp.view.recyclerview.adapter.OnItemClickListener

/**
 * Author: jc.lu
 * Date: 2018/1/14.
 */
class PersonAdapter(mContext: Context, personList: ArrayList<Person>?, layoutId: Int) : CommonAdapter<Person>(mContext, personList!!, layoutId) {

    //使用接口回调点击事件
    private var mItemClickListener: OnItemClickListener? = null

    override fun bindData(holder: ViewHolder, data: Person, position: Int) {
        holder.setText(R.id.person_name,data.name)
        if(position == 1) {
            holder.setText(R.id.person_id,"这是最后一条")
        } else {
            holder.setText(R.id.person_id,data.id.toString())
        }
        holder.setOnItemClickListener(View.OnClickListener { Log.d("jc.lu","click") })
        holder.getView<TextView>(R.id.person_id).setOnClickListener(View.OnClickListener {
            mItemClickListener?.onItemClick(mData[position], position)
        })

    }

    fun addData(person: Person) {
        this.mData.add(person)
        notifyDataSetChanged()
    }




}